package  
{
	import bulletbehavior.AccelerateXYBehavior;
	import bulletbehavior.HomeTargetBehavior;
	import bulletbehavior.TypeCyclingBehavior;
	import turretbehavior.SpinningTurretBehavior;
	import turretbehavior.TypeCyclingTurretBehavior;
	import bulletbehavior.SetAngleBehavior;
	import turrets.BurstTurret
	import org.flixel.FlxG;
	/**
	 * ...
	 * @author morgan
	 */
	public class Stage2State extends GameState
	{
	
		[Embed (source = "../data/tutorial_appetite.png")] private var tut4:Class;		
		
		public function Stage2State() 
		{
			super()
			levelName = "1-2"
			levelIndex = 1;
			chefName = "al dente";
			img_terrain = img_terrain_1;		
		}
		
		override public function setupBoss():void 
		{
			boss = new Boss(FlxG.width / 2 - 70, 10, 0);
			
			var straight:BulletPattern = new BulletPattern();
			var accel:BulletPattern = new BulletPattern();
			accel.addBehavior(new AccelerateXYBehavior(0, 100), 0.5, 2.5);
			
			var briefHome:BulletPattern = new BulletPattern();
			briefHome.addBehavior(new HomeTargetBehavior(player, -1), 0.5, 0.6);
			
			var redirectDown:BulletPattern = new BulletPattern();
			redirectDown.addBehavior(new SetAngleBehavior(90), 0.6);
			
			var redirectLeft:BulletPattern = new BulletPattern();
			redirectLeft.addBehavior(new SetAngleBehavior(180), 1.0);
			
			var p1f:BossPattern = new BossPattern();
			for (var i:int = 0; i < 5; i++)
			{
				var t:BurstTurret = new BurstTurret(i * 20 - 40, 0, accel, i % 3, 110 - i * 8, 20, 2.0, 3, 0.2);
				t.addBehavior(new TypeCyclingTurretBehavior(2, [i%3,(i+1)%3,(i+2)%3]))
				p1f.addTurretTime(2, Infinity, t);
			}
			
			
			
			var p2f:BossPattern = new BossPattern();
			var t1t:Turret = new Turret(-10, 0, briefHome, 0, 90, 80, 1);
			t1t.addBehavior(new TypeCyclingTurretBehavior(1, [0, 1, 2]));
			var t2t:Turret = new Turret(0, -10, briefHome, 0, 90, 80, 1);
			t2t.addBehavior(new TypeCyclingTurretBehavior(1, [2, 0, 1]));
			var t3t:Turret = new Turret(10, 0, briefHome, 0, 90, 80, 1);
			t3t.addBehavior(new TypeCyclingTurretBehavior(1, [1, 2, 0]));
			p2f.addTurretTime(0, Infinity, t1t); p2f.addTurretTime(0, Infinity, t2t); p2f.addTurretTime(0, Infinity, t3t);
			
			var t4t:Turret = new Turret(0, -20, straight, 0, 0, 50, 0.25);
			t4t.addBehavior(new SpinningTurretBehavior(180));
			t4t.addBehavior(new TypeCyclingTurretBehavior(4.0, [0, 1, 2]));
			p2f.addTurretTime(15, Infinity, t4t);
			
			
			var p3f:BossPattern = new BossPattern();
			var t5t:Turret = new Turret(-30, -10, redirectDown, 0, 0, 80, 0.2);
			t5t.addBehavior(new SpinningTurretBehavior(360));
			t5t.addBehavior(new TypeCyclingTurretBehavior(4.0, [0, 1, 2, 2, 1, 0]));
			p3f.addTurretTime(0, Infinity, t5t);
			var t7t:Turret = new Turret(30, -10, redirectDown, 0, 0, 80, 0.2);
			t7t.addBehavior(new SpinningTurretBehavior(360));
			t7t.addBehavior(new TypeCyclingTurretBehavior(4.0, [0, 1, 2, 2, 1, 0]));
			p3f.addTurretTime(15.1, Infinity, t7t);			
			
			
			var p4f:BossPattern = new BossPattern();
			for (i = 0; i < 3; i++)
			{
				for (var j:int = 0; j < 3; j++)
				{
					var tx:Turret = new Turret(((i * 3) + j) * 10 - 40, 0, straight, i, 90, 90, 1);
					tx.addBehavior(new TypeCyclingTurretBehavior(0.5, [i % 3, (i + 1) % 3, (i + 2) % 3]));
					p4f.addTurretTime(i / 4, 1 + i / 4, tx);
					var ty:Turret = new Turret(((i * 3) + j) * 10 - 40, 0, straight, (i + 1) % 3, 90, 50, 5);
					ty.addBehavior(new SpinningTurretBehavior( 4.5-((i * 3) + j)));
					p4f.addTurretTime(1 + (i * 3 + j) / 9.0, 4, ty);
					p4f.setPatternLength(4);
				}
			}
			
			boss.addState(new BossState(1000, p1f));
			boss.addState(new BossState(700, p4f));
			boss.addState(new BossState(800, p2f));
			boss.addState(new BossState(1400, p3f));
		}
		
		override public function update():void 
		{
			super.update();
			if (!Saving.showedRainbowTut && time < 3 && time + FlxG.elapsed >= 3)
			{
				showTutorial(tut4);
				Saving.showedRainbowTut = true;
			}
		}		
	}

}